package demo;



import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import java.io.Writer;
import java.util.List;

import org.htmlcleaner.TagNode;
import org.htmlcleaner.XPatherException;

import dao.WebsiteDAO;

import lib.ConnectionWeb;
import lib.OneMenuHasClickFilter;
import lib.OneMenuNoClickFilter;
import lib.StringEdit;
import lib.TwoMenuFilter;

public class demo5 {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		WebsiteDAO dao= new WebsiteDAO();
		dao.insert2("dasd","dasd", "asd", "adsdsa");
		
		
		// TODO Auto-generated method stub
		String url="http://www.vinabook.com/nghich-ly-an-do-m11i53417.html";
		ConnectionWeb con= new ConnectionWeb();
		String xpath="tr/td/h1";
		String xp="div align=\"justify\" style=\"padding-left:30px; line-height:15px\"/p";
		String xpp="td valign=\"top\" align=\"left\"/h1";
		xpp=StringEdit.EditXpath(xpp);
		TagNode root=con.getInfo(url);
		List<TagNode> l=con.executeXpath2(root, xpp,6);
		
		for(int i=0; i< l.size();i++)
		{
			TagNode t=l.get(i);
			
			Writer out2;
			List<?> l2=t.getChildTagList();
			String st="";
			for(int j= 0;j< l2.size();j++)
			{
				TagNode t2=(TagNode) l2.get(j);
				st=st+t2.getText().toString()+"\n";
			}
				
			
			try {
				out2 = new BufferedWriter(new OutputStreamWriter(
						new FileOutputStream("E:\\noidung2.txt",true),"UTF-8"));
				out2.write(st);
				out2.close();
			} catch (UnsupportedEncodingException | FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}	
			
			
		}
		
	//	TwoMenuFilter fil= new TwoMenuFilter();
	//	OneMenuHasClickFilter fil=new OneMenuHasClickFilter();

	
	}

}
